{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4, 2, 4, 6, 8, 10]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [ 0, 1, 2, 3, 4]\n",
    "b = [ 2,  4,  6,  8, 10]\n",
    "a.extend(b)  #[0, 1, 2, 3, 4, 2, 4, 6, 8, 10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2, 3, 4, 2, 4, 6, 8, 10, 2, 4, 6, 8, 10]\n"
     ]
    }
   ],
   "source": [
    "for i in b:\n",
    "    a.append(i)\n",
    "print(a)  #[0, 1, 2, 3, 4, 2, 4, 6, 8, 10, 2, 4, 6, 8, 10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[[0, 1, 2, 3, 4], [2, 4, 6, 8, 10]]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [ 0, 1, 2, 3, 4]\n",
    "b = [ 2,  4,  6,  8, 10]\n",
    "c=[a,b]\n",
    "c  #[[0, 1, 2, 3, 4], [2, 4, 6, 8, 10]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[[0, 2], [1, 4], [2, 6], [3, 8], [4, 10]]]\n"
     ]
    }
   ],
   "source": [
    "c = []\n",
    "for i in range(len(a)):\n",
    "    c.append([a[i],b[i]])\n",
    "c = [c]\n",
    "print(c)  #[[[0, 2], [1, 4], [2, 6], [3, 8], [4, 10]]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[ 0,  2],\n",
       "        [ 1,  4],\n",
       "        [ 2,  6],\n",
       "        [ 3,  8],\n",
       "        [ 4, 10]]])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "a = np.array(c)\n",
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr1 = np.arange(0,5) #array([0, 1, 2, 3, 4])\n",
    "arr2 = np.arange(2,11,2) #array([ 2,  4,  6,  8, 10])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0,  1,  2,  3,  4,  2,  4,  6,  8, 10])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.hstack((arr1,arr2))  #组成一个新的一维数组\n",
    "arr  #array([ 0,  1,  2,  3,  4,  2,  4,  6,  8, 10])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4,  0,  1,  2,  3,  4],\n",
       "       [ 2,  4,  6,  8, 10,  2,  4,  6,  8, 10]])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.vstack((arr1,arr2)) #组成一个新的二维数组\n",
    " #array([[ 0,  1,  2,  3,  4],[ 2,  4,  6,  8, 10]])\n",
    "arr = np.hstack((arr,arr))\n",
    "arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[ 0,  2],\n",
       "        [ 1,  4],\n",
       "        [ 2,  6],\n",
       "        [ 3,  8],\n",
       "        [ 4, 10]]])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.dstack((arr1,arr2)) #组成一个新的三维数组\n",
    "arr #array([[[ 0,  2],[ 1,  4],[ 2,  6],[ 3,  8],[ 4, 10]]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4],\n",
       "       [ 2,  4,  6,  8, 10]])"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.vstack((arr1,arr2)) #组成一个新的二维数组\n",
    " #array([[ 0,  1,  2,  3,  4],[ 2,  4,  6,  8, 10]])\n",
    "arr = np.row_stack((arr1,arr2))\n",
    "arr  #array([[ 0,  1,  2,  3,  4],[ 2,  4,  6,  8, 10]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  2],\n",
       "       [ 1,  4],\n",
       "       [ 2,  6],\n",
       "       [ 3,  8],\n",
       "       [ 4, 10]])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.column_stack((arr1,arr2))  #列组合\n",
    "arr  #array([[ 0,  2],[ 1,  4],[ 2,  6],[ 3,  8],[ 4, 10]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4],\n",
       "       [ 2,  4,  6,  8, 10],\n",
       "       [ 0,  1,  2,  3,  4]])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "arr = np.row_stack((arr1,arr2,arr1))\n",
    "arr #"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "np.vstack?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 1, 2, 3, 4, 2, 4, 6, 8])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [ 0, 1, 2, 3, 4]\n",
    "b = [ 2,  4,  6,  8]\n",
    "arr = np.hstack((a,b))\n",
    "arr  #array([0, 1, 2, 3, 4, 2, 4, 6, 8])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "np.*stack?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ True,  True,  True,  True,  True],\n",
       "       [ True,  True,  True,  True,  True]])"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.row_stack((arr1,arr2)) == np.vstack((arr1,arr2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\users\\feng_sun\\appdata\\local\\programs\\python\\python37-32\\lib\\site-packages\\ipykernel_launcher.py:1: DeprecationWarning: elementwise comparison failed; this will raise an error in the future.\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.column_stack((arr1,arr2)) == np.hstack((arr1,arr2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-73-cb9b3e70e97a>, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-73-cb9b3e70e97a>\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m    b = a.reshape(,9)\u001b[0m\n\u001b[1;37m                  ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "a = np.array([0, 1, 2, 3, 4, 2, 4, 6, 8])\n",
    "b = a.reshape()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3  4]\n",
      " [ 2  4  6  8 10]]\n",
      "[[ 2  3  4  5  6]\n",
      " [ 4  6  8 10 12]]\n"
     ]
    }
   ],
   "source": [
    "arr3 = np.vstack((arr1,arr2))\n",
    "arr4 = arr3 + 2\n",
    "print(arr3)\n",
    "print(arr4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4],\n",
       "       [ 2,  4,  6,  8, 10],\n",
       "       [ 2,  3,  4,  5,  6],\n",
       "       [ 4,  6,  8, 10, 12]])"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.vstack((arr3,arr4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4],\n",
       "       [ 2,  4,  6,  8, 10],\n",
       "       [ 2,  3,  4,  5,  6],\n",
       "       [ 4,  6,  8, 10, 12]])"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.row_stack((arr3,arr4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\users\\feng_sun\\appdata\\local\\programs\\python\\python37-32\\lib\\site-packages\\ipykernel_launcher.py:1: DeprecationWarning: elementwise comparison failed; this will raise an error in the future.\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.column_stack((arr1,arr2)) == np.hstack((arr1,arr2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "         True],\n",
       "       [ True,  True,  True,  True,  True,  True,  True,  True,  True,\n",
       "         True]])"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.column_stack((arr3,arr4)) == np.hstack((arr3,arr4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
